/**
 * 
 */
package org.statewalker.parser.wiki.tokenizer.block;

import org.statewalker.parser.wiki.tokenizer.base.StreamToken;
import org.statewalker.tokenizer.base.AbstractTokenizer;
import org.statewalker.tokenizer.base.ITokenFactory;
import org.statewalker.tokenizer.stream.ICharStream;
import org.statewalker.tokenizer.stream.ICharStream.IMarker;

public class HorlineTokenizer extends AbstractTokenizer<StreamToken> {

    public HorlineTokenizer(ITokenFactory<StreamToken> factory) {
        super(factory);
    }

    protected boolean checkChar(char ch) {
        return ch == '-';
    }

    public StreamToken read(ICharStream stream) {
        StreamToken result = null;
        IMarker marker = stream.markPosition();
        try {
            char ch = stream.getChar();
            while (checkChar(ch)) {
                stream.incPos();
                ch = stream.getChar();
            }
            int len = stream.getPointer().len(marker.getPointer());
            result = len >= 3 ? newToken(stream, marker) : null;
            return result;
        } finally {
            marker.close(result == null);
        }
    }
}